home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / daten / db / examples / arexxdemos / expandii.db < prev    next >
Text File  |  1994-09-25  |  2KB  |  74 lines

  1. /* Rexxprogram for db that expands some shortcuts  */
  2. /* This one opens a file with 'aliases', one per line, the first word */
  3. /* being the word to expand, and the rest of the line being what to */
  4. /* expand into */
  5. /* User may enter one or more words to expand in one field */
  6.  
  7.  
  8. Options Results
  9. GETFIELD
  10. shortwords = result
  11. expwords = ''
  12.  
  13. if word(shortwords,1) = '+' then do
  14.     call delete_word(word(shortwords,2))
  15.     if open('file', 'expandwordlist', Append) then do
  16.         nil = writeln('file', subword(shortwords,2))
  17.         nil = close('file')
  18.         exit
  19.     end
  20. end
  21.  
  22. if word(shortwords,1) = '-' then do
  23.     call delete_word(word(shortwords,2))
  24.     exit
  25. end
  26.  
  27. do i = 1 to words(shortwords)
  28.     shortword = word(shortwords, i)
  29.     found = 'no'
  30.     if open('file', 'expandwordlist', Read) then do
  31.         do while eof('file') = 0
  32.         line = readln('file')
  33.             if upper(word(line, 1)) = upper(shortword) then do
  34.                 expwords = expwords subword(line, 2)
  35.                 found = 'yes'
  36.                 leave
  37.             end
  38.         end
  39.     end
  40.     nil = close('file')
  41.     if found = 'no' then expwords = expwords shortword
  42. end
  43. PUTFIELD strip(expwords)
  44. exit
  45.  
  46.  
  47. delete_word:
  48.     arg delw        /* ARexx converts all arguments to UPPER :-( */
  49.     if open('in', 'expandwordlist', Read) then do
  50.         if open('out', 't:' || 'expandwordlist', Write) then do
  51.             do while eof('in') = 0
  52.                 line = readln('in')
  53.                 if line ~= '' then
  54.                     if upper(word(line, 1)) ~= delw then nil = writeln('out', line)
  55.             end
  56.             nil = close('out')
  57.         end
  58.         nil = close('in')
  59.     end
  60.     if open('in', 't:' || 'expandwordlist', Read) then do
  61.         if open('out', 'expandwordlist', Write) then do
  62.             do while eof('in') = 0
  63.                 line = readln('in')
  64.                 if line ~= '' then
  65.                     nil = writeln('out', line)
  66.             end
  67.             nil = close('out')
  68.         end
  69.         nil = close('in')
  70.     end
  71.     return
  72.     
  73.  
  74.